<template>
  <div class="list-table" style="height:100%;overflow-y:auto">
    <el-table v-loading="loading" :data="fundManageFeeDetailList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('出资人名称')" align="center" prop="userName" min-width="180" show-overflow-tooltip />
      <el-table-column :label="$t('出资人类型')" align="center" prop="investorsType" :formatter="investorsTypeOptionsFormat" min-width="140" show-overflow-tooltip />
      <el-table-column :label="$t('计算基数-实缴金额') + $t('金额单位')" align="center" prop="beginningPaidInAmount" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.beginningPaidInAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('计算基数-认缴金额') + $t('金额单位')" align="center" prop="subscribedAmount" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.subscribedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('计算基数-在投金额') + $t('金额单位')" align="center" prop="beginningReinvestedAmount" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.beginningReinvestedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理费金额') + $t('金额单位')" align="center" prop="managementFee" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.managementFee, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:detail:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['fund:detail:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改基金管理费对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundManageFeeDetailForm ref="fundManageFeeDetailForm" />
    </el-dialog>
  </div>
</template>

<script>
import { delFundManageFeeDetail, listFundManageFeeDetail } from '@/api/fund/manageFeeDetail/fundManageFeeDetail'
import fundManageFeeDetailForm from './fundManageFeeDetailForm'
export default {
    components: {
      fundManageFeeDetailForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 管理费明细表格数据
          fundManageFeeDetailList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          investorsTypeOptions: [],
          // 查询参数
          queryParams: {
              managementId: undefined,
              fundId: undefined,
              investorId: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
    // 出资人类型字典
    this.getDicts('fund_investor_type').then(response => {
      response.data.forEach(item => {
        this.investorsTypeOptions.push(item)
      })
    })
  },
  methods: {
    /** 查询管理费明细列表 */
    getList() {
        this.loading = true
        listFundManageFeeDetail(this.queryParams).then(response => {
            this.fundManageFeeDetailList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 出资人类型
    investorsTypeOptionsFormat(row) {
      return this.selectDictLabel(this.investorsTypeOptions, row.investorsType)
    },
    getManageFeeDetail(row) {
        this.loading = true
        this.queryParams.managementId = row.id
        listFundManageFeeDetail(this.queryParams).then(response => {
            this.fundManageFeeDetailList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            managementId: undefined,
            fundId: undefined,
            investorId: undefined,
            userName: undefined,
            beginningPaidInAmount: undefined,
            subscribedAmount: undefined,
            beginningReinvestedAmount: undefined,
            managementFee: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.title = this.$t('修改管理费明细')
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundManageFeeDetailForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delFundManageFeeDetail(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
